import request from './request'

/**
 * 获取未解答问题列表
 * @param {number} page - 页码
 * @param {number} size - 每页数量
 * @returns {Promise}
 */
export const getUnansweredQuestions = (page, size) => {
  return request.get('/unanswered/list', {
    params: { page, size }
  })
}

/**
 * 提交人工解答
 * @param {number} questionId - 问题ID
 * @param {string} answer - 解答内容
 * @param {number} userId - 用户ID
 * @returns {Promise}
 */
export const submitAnswer = (questionId, answer, userId) => {
  return request.post(`/unanswered/${questionId}/answer`, { answer, userId })
}

/**
 * 对解答评分
 * @param {number} answerId - 解答ID
 * @param {string} rating - 评分（useful/useless）
 * @param {number} userId - 用户ID
 * @returns {Promise}
 */
export const rateAnswer = (answerId, rating, userId) => {
  return request.post(`/unanswered/answer/${answerId}/rate`, { rating, userId })
}

/**
 * 获取某问题的所有解答
 * @param {number} questionId - 问题ID
 * @returns {Promise}
 */
export const getAnswers = async (questionId) => {
  const response = await request.get(`/unanswered/${questionId}/answers`)
  return response.answers || []
}

/**
 * 手动触发同步高分答案到Dify知识库
 * @returns {Promise}
 */
export const syncToKnowledgeBase = () => {
  return request.post('/unanswered/sync-to-knowledge-base')
}
